package cn.ckx.coding.moudle.user.config;

import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @ClassName RabbitMqDelayConfig
 * @Description rabbitMQ延迟交换机配置
 * @Author c
 * @Date 2020/12/25
 * @Version 1.0
 **/
@Configuration
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class RabbitMqDelayConfig {
    
    public static final String DELAY_EXCHANGE = "ques.delay.exchange";
    
    public static final String DELAY_ROUTING_KEY = "ques.delay.routingKey.test1";

    public static final String DELAY_QUEUE = "ques.delay.queue.test1";

    public static final String DELAY_ROUTING_KEY_2 = "ques.delay.routingKey.test2";

    public static final String DELAY_QUEUE_2 = "ques.delay.queue.test2";

    @Bean
    public CustomExchange delayMessageExchange() {
        Map<String, Object> args = Maps.newHashMap();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAY_EXCHANGE, "x-delayed-message", false, false, args);
    }

    @Bean
    public Queue delayMessageQueue() {
        return new Queue(DELAY_QUEUE, false, false, false);
    }


    @Bean
    public Binding bindingDelayExchangeAndQueue() {
        return BindingBuilder.bind(delayMessageQueue()).to(delayMessageExchange()).with(DELAY_ROUTING_KEY).noargs();
    }

    
}
